import Vue from "vue";
import App from "./App.vue";
import {
  Button,
  Radio,
  Container,
  Main,
  Header,
  Aside,
  Menu,
  Submenu,
  MenuItemGroup,
  MenuItem,
  Dropdown,
  DropdownMenu,
  DropdownItem,
  Row,
  Col,
  Card,
  Table,
  TableColumn,
  Breadcrumb,
  BreadcrumbItem,
  Tag,
  Form,
  FormItem,
  Input,
  Select,
  Option,
  Switch,
  DatePicker,
  Dialog,
  Pagination,
  MessageBox,
  Message

} from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "./assets/less/index.less";

import router from "./router";
import store from "./store";
import http from "axios";
import "../api/mock.js";

import LemonIMUI from "lemon-imui";
import "lemon-imui/dist/index.css";
Vue.use(LemonIMUI);

Vue.config.productionTip = false;
Vue.use(Button);
Vue.use(Radio);
Vue.use(Container);
Vue.use(Main);
Vue.use(Header);
Vue.use(Aside);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItemGroup);
Vue.use(MenuItem);
Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Row);
Vue.use(Col);
Vue.use(Card);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
Vue.use(Tag);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Input);
Vue.use(Select);
Vue.use(Option);
Vue.use(Switch);
Vue.use(DatePicker);
Vue.use(Dialog);
Vue.use(Pagination);

// 在Vue的原型对象上添加http
Vue.prototype.$http = http;
Vue.prototype.$confirm = MessageBox.confirm
Vue.prototype.$message = Message

router.beforeEach((to, from, next) => {
  if(to.meta.title) {
    document.title=to.meta.title
  }
  store.commit('getToken') //防止页面刷新后vuex丢失token信息
  const token = store.state.user.token
  if(!token && to.name !== 'login') {
    next({name: 'login'})
  } else if(token && to.name === 'login'){
    next({name: 'home'})
  } else {
    next()
  }
})

new Vue({
  render: (h) => h(App),
  router,
  store,
  created() {
    store.commit('addMenu', router)
      document.title="逸悟"
  }
}).$mount("#app");
